﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Mapenect.Data;
using Mapenect.GesturePatterns;
using OpenNI;
using System.Runtime.InteropServices;
using System.Diagnostics;

namespace Mapenect.GestureInterpreter
{
    class SoundInterpreter : Interpreter
    {
        [DllImport("kernel32.dll")]
        public static extern bool Beep(int Frequenz, int Dauer);

        int frequ, duration;

        public SoundInterpreter(DataContainer data, float thres) : base(data, null, thres)
        {
            this.GestureDetected += new GestureEventhandler(AfterGestureDetected);
        }

        protected override bool checkForGesture()
        {
            MyJoint leftHand = jointData.getUserData(user.user1)[SkeletonJoint.LeftHand].GetLastElement();
            //MyJoint torso = jointData.getUserData(user.user1)[SkeletonJoint.Torso].GetLastElement();
            frequ = (int)(1000 + leftHand.Y);
            duration = (int)(1000 + leftHand.X);
            Debug.WriteLine(leftHand.X + ", " + leftHand.Y);
            return true;
        }

        private void AfterGestureDetected(object sender, EventArgs e)
        {
            Beep(frequ, duration);
        }
    }
}
